package com.lanhu.designpattern.delegation.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * author:zhangzg
 * date:2020/11/9 15:26
 */
public class DispatcherServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
        doDispatch(req, resp);
    }

    private void doDispatch(HttpServletRequest req, HttpServletResponse resp) {
        String uri = req.getRequestURI();
        String id = req.getParameter("id");
        if (uri.equalsIgnoreCase("getStudentById")){
            new StudentController().getById(id);
        }
        if (uri.equalsIgnoreCase("getTeacherById")){
            new TeacherController().getById(id);
        }
    }
}
